package com.example.bpmn.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
public class RedissonConfig {
    
    @Value("${spring.redis.host}")
    private String host;
    
    @Value("${spring.redis.port}")
    private int port;
    
    @Bean
    public RedissonClient redissonClient() {
        try {
            Config config = new Config();
            String address = String.format("redis://%s:%d", host, port);
            log.info("Connecting to Redis at {}", address);
            
            config.useSingleServer()
                .setAddress(address)
                .setConnectTimeout(5000)
                .setRetryAttempts(3)
                .setRetryInterval(1500);
                
            return Redisson.create(config);
        } catch (Exception e) {
            log.error("Failed to create RedissonClient", e);
            throw new RuntimeException("Could not create RedissonClient", e);
        }
    }
} 